

function convertTimestampToDate (timestamp) {
  // 创建Date对象
  var date = new Date(timestamp) // 注意：时间戳通常是秒为单位，所以需要乘以1000转换成毫秒

  // 获取年、月、日、小时、分钟、秒
  var year = date.getFullYear()
  var month = ('0' + (date.getMonth() + 1)).slice(-2) // 注意月份是从0开始的，需要加1，并且保证两位数
  var day = ('0' + date.getDate()).slice(-2)
  // var hours = ("0" + date.getHours()).slice(-2);
  // var minutes = ("0" + date.getMinutes()).slice(-2);
  // var seconds = ("0" + date.getSeconds()).slice(-2);

  // 返回格式化的日期时间字符串
  return year + '-' + month + '-' + day
  // + " " + hours + ":" + minutes + ":" + seconds;
}

function randomNum (minNum, maxNum) {
  switch (arguments.length) {
    case 1:
      return parseInt(Math.random() * minNum + 1, 10)
      break
    case 2:
      return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10)
      break
    default:
      return 0
      break
  }
}

const createTime = (count = 10) => {
  const day = 24 * 60 * 60 * 1000
  const start = '2023-01-01'
  const timeStamp = []
  const days = []
  for (let i = 0; i < count; i++) {
    let base = timeStamp[i - 1] || +new Date(start)
    let s = base + day
    timeStamp.push(s)
  }
  timeStamp.forEach(item => {
    days.push(convertTimestampToDate(item))
  })
  return {
    timeStamp,
    days,
  }
}

const createData = (count = 10) => {
  const result = []
  for (let i = 0; i < count; i++) {
    const r = randomNum(3, 6)
    result.push(r)
  }
  return result
}

export  {
  convertTimestampToDate,
  randomNum,
  createData,
  createTime
}
